#define _CRT_SECURE_NO_WARNINGS 1
/**
 * Definition for a binary tree node.
 * struct TreeNode {
 *     int val;
 *     struct TreeNode *left;
 *     struct TreeNode *right;
 * };
 */
int TreeSize(struct TreeNode* root)
{
    return root == NULL ? 0 : TreeSize(root->left) +
        TreeSize(root->right) + 1;
}

int TreeSum(struct TreeNode* root)
{
    if (root == NULL)
        return 0;

    return root->val + TreeSum(root->left) + TreeSum(root->right);
}
bool isUnivalTree(struct TreeNode* root)
{
    int size = TreeSize(root);
    int exam = root->val;
    if (size * exam == TreeSum(root))
        return true;
    else
        return false;
}